<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="col-md-12">
        <form id="sysNewsForm" method="post" class="form m-t" @submit.prevent="save()" accept-charset="UTF-8">
          <input type="hidden" name="id" v-model="id"/>
          <input type="hidden" name="token" v-model="item.token"/>
          <input type="hidden" name="newFlag" v-model="newFlag"/>
          <input type="hidden" name="type" value="0">
          <input type="hidden" name="isTop" value="0">
          <input type="hidden" name="state" value="1">
          <div class="clearfix "></div>
          <div class="col-md-12">
            <div class="form-group clearfix">
              <label class="col-md-8 control-label">标题：</label>
              <div class="col-md-12">
                <input id="bean-title" name="title" v-model="item.title" class="form-control" type="text" placeholder="请输入标题" required="" aria-required="true" aria-describedby="bean-title-error" maxlength="155" aria-invalid="true">
              </div>
            </div>
            <div class="form-group clearfix">
              <label class="col-md-8 control-label">内容：</label>
              <div class="col-md-12">
                <vue-ueditor-wrap :config="ueConfig" aria-describedby="bean-detailInfo-error" aria-invalid="true" id="bean-detailInfo" name="detailInfo" placeholder="请输入内容" style="width: 100%;" v-model="item.detailInfo"></vue-ueditor-wrap>
              </div>
            </div>
          </div>
          <div class="clearfix "></div>
          <div class="col-12 text-center" style="height: 50px;">
            <div>
              <input class="btn btn-primary" type="submit" value="保存"/>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import '@/assets/css/style.css'

import $ from '@/assets/js/jquery-vendor.js'
import axios from 'axios'
import '@/assets/js/validate/validation-vendor.js'
import VueUeditorWrap from 'vue-ueditor-wrap'
import {apiUtil, axiosContentType, site, ueConfig} from '@/assets/js/boss'

export default {
  components: {
    VueUeditorWrap
  },
  data() {
    return {
      id: 100000000000012306,
      item: {},
      newFlag: 0,
      uuidToken: '',
      ueConfig: ueConfig
    }
  },
  mounted() {
    let that = window.$vueApp = this;
    document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
    $('#sysNewsForm').validate();
    that.staff.init(function () {
      that.uuidToken = apiUtil.guid();
      that.info();
    });
  },
  methods: {
    info() {
      let that = this;
      axios.get(site.sysNews.info + that.id, {}).then(function (response) {
        const result = response.data;
        if (result.code === 0) {
          that.item = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    save() {
      // let that = this;
      if ($('#sysNewsForm').valid()) {
        axios.post(site.sysNews.save, $('#sysNewsForm').serialize(),
          axiosContentType.xWwwFormUrlencoded).then(function (response) {
          const result = response.data;
          if (result.code === 0) {
            // parent.$vueApp.page();
            alert('保存成功!');
            // that.lbox.closeMyBoxLayer()
          } else {
            alert(result.message);
          }
        });
      }
    }
  }
}
</script>

